All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sun.server.util.CharacterEncoder

java.lang.Object
   |
   +----sun.server.util.CharacterEncoder

public abstract class CharacterEncoder
extends Object
This class defines the encoding half of character encoders. A character encoder is an algorithim for transforming 8 bit binary data into text (generally 7 bit ASCII or 8 bit ISO-Latin-1 text) for transmition over text channels such as e-mail and network news. The character encoders have been structured around a central theme that, in general, the encoded text has the form:
	[Buffer Prefix]
	[Line Prefix][encoded data atoms][Line Suffix]
	[Buffer Suffix]
 
In the CharacterEncoder and CharacterDecoder classes, one complete chunk of data is referred to as a buffer. Encoded buffers are all text, and decoded buffers (sometimes just referred to as buffers) are binary octets. To create a custom encoder, you must, at a minimum, overide three abstract methods in this class.
bytesPerAtom which tells the encoder how many bytes to send to encodeAtom
encodeAtom which encodes the bytes sent to it as text.
bytesPerLine which tells the encoder the maximum number of bytes per line.
Several useful encoders have already been written and are referenced in the See Also list below.

See Also:
CharacterDecoder;, UCEncoder, UUEncoder, BASE64Encoder

Variable Index

 o pStream
Stream that understands "printing"

Constructor Index

 o CharacterEncoder()

Method Index

 o bytesPerAtom()
Return the number of bytes per atom of encoding
 o bytesPerLine()
Return the number of bytes that can be encoded per line
 o encode(byte[])
A 'streamless' version of encode that simply takes a buffer of bytes and returns a string containing the encoded buffer.
 o encode(byte[], OutputStream)
Encode the buffer in aBuffer and write the encoded result to the OutputStream aStream.
 o encode(InputStream, OutputStream)
Encode bytes from the input stream, and write them as text characters to the output stream.
 o encodeAtom(OutputStream, byte[], int, int)
Encode one "atom" of information into characters.
 o encodeBuffer(byte[])
A 'streamless' version of encode that simply takes a buffer of bytes and returns a string containing the encoded buffer.
 o encodeBuffer(byte[], OutputStream)
Encode the buffer in aBuffer and write the encoded result to the OutputStream aStream.
 o encodeBuffer(InputStream, OutputStream)
Encode bytes from the input stream, and write them as text characters to the output stream.
 o encodeBufferPrefix(OutputStream)
Encode the prefix for the entire buffer.
 o encodeBufferSuffix(OutputStream)
Encode the suffix for the entire buffer.
 o encodeLinePrefix(OutputStream, int)
Encode the prefix that starts every output line.
 o encodeLineSuffix(OutputStream)
Encode the suffix that ends every output line.
 o readFully(InputStream, byte[])
This method works around the bizarre semantics of BufferedInputStream's read method.

Variables

 o pStream
 protected PrintStream pStream
Stream that understands "printing"

Constructors

 o CharacterEncoder
 public CharacterEncoder()

Methods

 o bytesPerAtom
 protected abstract int bytesPerAtom()
Return the number of bytes per atom of encoding

 o bytesPerLine
 protected abstract int bytesPerLine()
Return the number of bytes that can be encoded per line

 o encodeBufferPrefix
 protected void encodeBufferPrefix(OutputStream aStream) throws IOException
Encode the prefix for the entire buffer. By default is simply opens the PrintStream for use by the other functions.

 o encodeBufferSuffix
 protected void encodeBufferSuffix(OutputStream aStream) throws IOException
Encode the suffix for the entire buffer.

 o encodeLinePrefix
 protected void encodeLinePrefix(OutputStream aStream,
                                 int aLength) throws IOException
Encode the prefix that starts every output line.

 o encodeLineSuffix
 protected void encodeLineSuffix(OutputStream aStream) throws IOException
Encode the suffix that ends every output line. By default this method just prints a into the output stream.

 o encodeAtom
 protected abstract void encodeAtom(OutputStream aStream,
                                    byte someBytes[],
                                    int anOffset,
                                    int aLength) throws IOException
Encode one "atom" of information into characters.

 o readFully
 protected int readFully(InputStream in,
                         byte buffer[]) throws IOException
This method works around the bizarre semantics of BufferedInputStream's read method.

 o encode
 public void encode(InputStream inStream,
                    OutputStream outStream) throws IOException
Encode bytes from the input stream, and write them as text characters to the output stream. This method will run until it exhausts the input stream.

 o encode
 public void encode(byte aBuffer[],
                    OutputStream aStream) throws IOException
Encode the buffer in aBuffer and write the encoded result to the OutputStream aStream.

 o encode
 public String encode(byte aBuffer[])
A 'streamless' version of encode that simply takes a buffer of bytes and returns a string containing the encoded buffer.

 o encodeBuffer
 public void encodeBuffer(InputStream inStream,
                          OutputStream outStream) throws IOException
Encode bytes from the input stream, and write them as text characters to the output stream. This method will run until it exhausts the input stream. It differs from encode in that it will add a newline at the end of any buffer it encodes, even if that buffer is shorter than bytesPerLine.

 o encodeBuffer
 public void encodeBuffer(byte aBuffer[],
                          OutputStream aStream) throws IOException
Encode the buffer in aBuffer and write the encoded result to the OutputStream aStream.

 o encodeBuffer
 public String encodeBuffer(byte aBuffer[])
A 'streamless' version of encode that simply takes a buffer of bytes and returns a string containing the encoded buffer.


All Packages  Class Hierarchy  This Package  Previous  Next  Index